using System;
using System.Collections.Generic;
using System.Text;
using SchEdu.Framework.DataModel;
using SchEdu.Framework.Exceptions;

namespace SchEdu.Framework.Validators
{

    public class OperationPerOrderValidator : Validator
    {
        int maxOperationPerOrder = -1;

        public int MaxOperationPerOrder
        {
            get { return maxOperationPerOrder; }
            set { maxOperationPerOrder = value; }
        }

        int minOperationPerOrder = -1;

        public int MinOperationPerOrder
        {
            get { return minOperationPerOrder; }
            set { minOperationPerOrder = value; }
        }

        public OperationPerOrderValidator(SchEduData schEduData, int minOperationPerOrder, int maxOperationPerOrder)
            : base(schEduData)
        {
            this.minOperationPerOrder = minOperationPerOrder;
            this.maxOperationPerOrder = maxOperationPerOrder;
        }
        #region IValidator Members

        public override void Validate()
        {
            foreach (SchEduDataSet.OrderRow order in SchEduData.Order)
            {
                int count = order.GetOperationRows().Length;
                if (minOperationPerOrder != -1 && count < minOperationPerOrder )
                {
                    throw new ValidatorException(string.Format(Resources.MinOperationPerOrder, order.OrderNo, minOperationPerOrder));
                }
                if (maxOperationPerOrder != -1 && count > maxOperationPerOrder)
                {
                    throw new ValidatorException(string.Format(Resources.MaxOperationPerOrder, order.OrderNo, maxOperationPerOrder));
                }
            }
        }

        #endregion
    }
}
